/*=+--+=#=+--     Unmanned Aerial System Management Software      --+=#=+--+=#*\
|          Copyright (C) 2011 Regents of the University of Colorado.           |
|                             All Rights Reserved.                             |

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.

            Jack Elston                       Cory Dixon                        
|           elstonj@colorado.edu              dixonc@colorado.edu              |
|                                                                              |
\*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*/

/***********************************************************************
 *
 * FILENAME:
 * gtk_gpsmap.c
 *
 * PURPOSE:
 *	Provide a GPS map interface to the user.
 *
 * LAST MODIFIED:
 *
 ***********************************************************************/

#ifndef __NWSWARNINGS_H
#define __NWSWARNINGS_H

#include <goocanvas.h>
#include <libsoup/soup.h>

#include "LayerManager.h"

#define WARN_DIR      "/opt/netuas/radar/warn"
#define WARN_ZIP_FILE WARN_DIR"/current_warnings.zip"

class NWSWarnings : public LayerManager
{
	typedef enum {
		STW_WARN = 0,
		TOR_WARN,
		FFW_WARN,
		NUM_WARN
	} WarnType_t;

	static const char *warn_color[NUM_WARN];
	static const char *warn_files[NUM_WARN];
	static const char *warn_names[NUM_WARN];

	private:
		bool initialized;
		bool haveNewWarn;

		// how we download the files
		SoupSession *soup_session;
	
		static gboolean update_warn_timeout(gpointer data);
		static void download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data);

		void updateWarningFile();
		void parseWarnFile(WarnType_t warn);
		void parseWarnings();

		GooCanvasItem *warn_groups[NUM_WARN];
		GooCanvasItem *poly_groups[NUM_WARN];

		double line_width;

	public:
		NWSWarnings();
		~NWSWarnings();

		// layer interface
		virtual void init(GPSMap *map = NULL);
		virtual void updateMap();
		virtual void translate_from_zoomChange(double zoom_factor);
		virtual bool setShown(int setTo = -1);

		void initWarnings();

		// The details of the downloaded file
		typedef struct {
			char        *uri;
			char        *folder;
			char        *filename;
			NWSWarnings *me;
		} download_t;
		 
};

#endif
